package com.quectel.mobile.controller.device;

import com.quectel.business.dms.device.DeviceBusiness;
import com.quectel.constant.global.SystemConstants;
import com.quectel.core.module.device.service.DeviceService;
import com.quectel.core.module.household.dto.HouseholdDto;
import com.quectel.core.module.household.service.HouseholdRoomService;
import com.quectel.core.module.household.service.HouseholdService;
import com.quectel.core.module.village.service.VillageRoomService;
import com.quectel.mobile.controller.BaseController;
import com.quectel.mobile.util.SessionHolder;
import com.quectel.util.common.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author rananxin
 * @email ryan.ran@quectel.com
 * @date 2022/1/10 2:35 下午
 */
@RestController
@RequestMapping("device")
@Tag(name = "DeviceController", description = "设备管理相关api")
public class DeviceController extends BaseController {

    @DubboReference
    private DeviceService deviceService;
    @DubboReference
    private HouseholdService householdService;
    @DubboReference
    private VillageRoomService villageRoomService;
    @DubboReference
    private HouseholdRoomService householdRoomService;
    @Autowired
    private DeviceBusiness deviceBusiness;

    @GetMapping("getKeys")
    @Operation(summary = "获取已绑定的门禁列表")
    public Response<Object> getKeys() {
        SessionHolder.checkHousehold();

        HouseholdDto currentHousehold = SessionHolder.getLoginMobileUserSession().getCurrentHousehold();
        if (currentHousehold == null) {
            return Response.error("未认证为住户");
        }

        return Response.ok().wrap(deviceBusiness.queryAuthEntranceGuardByPerson(SystemConstants.HOUSEHOLD, currentHousehold.getId()));
    }

    @PostMapping("openDoor")
    @Operation(summary = "远程开门")
    public Response<Object> openDoor(@RequestBody Long deviceId) {

        return Response.ok();
    }

}
